package cxp.xuexi.maven_shiro.configuration;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;

/**
 * Created by ASUS on 2018/2/20.
 */
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = {"cxp.xuexi.maven_shiro.controller"})
public class SpringmvcConfig extends WebMvcConfigurerAdapter{
  /*  @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/bootstrap/css*//**").addResourceLocations("classpath:/bootstrap/css/");
        registry.addResourceHandler("/bootstrap/js*//**").addResourceLocations("classpath:/bootstrap/js/");
        registry.addResourceHandler("/bootstrap/fonts*//**").addResourceLocations("classpath:/bootstrap/fonts/");
        super.addResourceHandlers(registry);
    }*/

    @Bean
    // 设置 InternalResourceViewResolver. 为跳转页面自动加上前缀及后缀
    public InternalResourceViewResolver jspViewResolver() {
        InternalResourceViewResolver jspViewResolver = new InternalResourceViewResolver();
        // 前缀
        jspViewResolver.setPrefix("/WEB-INF/jsp/");
        // 后缀
        jspViewResolver.setSuffix(".jsp");
        jspViewResolver.setViewClass(JstlView.class);
        return jspViewResolver;
    }

    /**
     * 静态资源处理
     * @param configurer
     */
    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        super.configureDefaultServletHandling(configurer);
        configurer.enable();
    }
}
